package com.code.zjm;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

/**
 * Created by ZJM on 2017/4/13.
 * 封装相同特性的activity
 */

public abstract class BaseActivity extends AppCompatActivity implements View.OnClickListener {
    protected Intent intent = new Intent();//意图，跳转

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(getTAG(), "onCreate: " + this);
        //动态设置视图
        if (null != getContentView()) {
            //若是图不为空 处理
            if (getContentView() instanceof Integer) {
                setContentView((Integer) getContentView());
            } else if (getContentView() instanceof View) {
                setContentView((View) getContentView());
            }
        } else {
            //视图为空的处理 生成一个空白界面
            View view = new View(this);
            view.setBackgroundColor(getResources().getColor(android.R.color.transparent));
            setContentView(view);
        }

        //初始化界面
        initView();
        //初始化监听器
        initListener();

    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.i(getTAG(), "onStart: >>>>" + this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.i(getTAG(), "onPause: >>>>" + this);
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.i(getTAG(), "onStop: >>>>" + this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.i(getTAG(), "onDestroy: >>>>" + this);
    }

    /**
     * 获取 TAG
     * @return String
     */
    protected abstract String getTAG();

    /**
     * 获取界面布局
     * @return Object
     */
    protected abstract Object getContentView();

    /**
     * 初始化界面
     */
    protected void initView() {
    }

    /**
     * 初始化监听器
     */
    protected void initListener() {
    }
}
